<!-- 新增或编辑 -->
 <template>
    <div style="max-height: 500px; overflow-y: auto">
        <Form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="150">
            <Row>
                <Col span="12">
                    <FormItem label="终端设备名称" prop="EQ_NAME">
                        <Input type="text" v-model="formValidate.EQ_NAME" placeholder="请输入终端设备名称"></Input>
                    </FormItem>
                </Col>
                <Col span="12">
                    <FormItem label="终端设备地址" prop="EQ_ADDRESS">
                        <Input type="text" v-model="formValidate.EQ_ADDRESS" placeholder="请输入终端设备地址"></Input> </FormItem
                ></Col>
            </Row>
            <Row>
                <Col span="12">
                    <FormItem label="所属网关" prop="GATEWAY_GUID">
                        <Select v-model="formValidate.GATEWAY_GUID" placeholder="请选择所属网关">
                            <Option :value="item.id" v-for="item in sswgList" v-bind:key="item.id">{{ item.text }}</Option>
                        </Select>
                    </FormItem></Col
                >
                <Col span="12">
                    <FormItem label="下行接口" prop="DOWN_INTERFACE">
                        <Select v-model="formValidate.DOWN_INTERFACE" placeholder="请选择下行接口">
                            <Option :value="item.value" v-for="item in xxjkList" v-bind:key="item.value">{{ item.label }}</Option>
                        </Select>
                    </FormItem>
                </Col>
            </Row>
            <Row>
                <Col span="12">
                    <FormItem label="参与时段控制" prop="TIME_CONTROL">
                        <RadioGroup v-model="formValidate.TIME_CONTROL">
                            <Radio label="0">否</Radio>
                            <Radio label="1">是</Radio>
                        </RadioGroup>
                    </FormItem>
                </Col>
                <Col span="12">
                    <FormItem label="是否加密" prop="ENCRYPT">
                        <RadioGroup v-model="formValidate.ENCRYPT">
                            <Radio label="0">否</Radio>
                            <Radio label="1">是</Radio>
                        </RadioGroup>
                    </FormItem>
                </Col>
            </Row>
            <Row>
                <!-- 字典：SBSCCJ -->
                <Col span="12">
                    <FormItem label="生产厂家" prop="FACTORY_ID">
                        <Select v-model="formValidate.FACTORY_ID" placeholder="请选择生产厂家">
                            <Option :value="item.value" v-for="item in sccjList" v-bind:key="item.value">{{ item.label }}</Option>
                        </Select>
                    </FormItem>
                </Col>
                <Col span="12">
                    <FormItem label="所属建筑" prop="BD_GUID">
                        <!--    :disable-branch-nodes="true"  禁用父级选择 -->
                        <treeselect
                            :options="options"
                            v-model="formValidate.BD_GUID"
                            :show-count="true"
                            placeholder="请选择所属建筑"
                        /> </FormItem
                ></Col>
            </Row>
            <Row>
                <Col span="12">
                    <FormItem label="协议类型" prop="PROTOCOL_TYPE">
                        <Select v-model="formValidate.PROTOCOL_TYPE" placeholder="请选择协议类型">
                            <Option :value="item.value" v-for="item in xylxList" v-bind:key="item.value">{{ item.label }}</Option>
                        </Select>
                    </FormItem>
                </Col>
                <Col span="12">
                    <FormItem label="检校方式" prop="VALIDATION">
                        <Select v-model="formValidate.VALIDATION" placeholder="请选择检校方式">
                            <Option :value="item.value" v-for="item in jyfsList" v-bind:key="item.value">{{ item.label }}</Option>
                        </Select>
                    </FormItem>
                </Col>
            </Row>
            <Row>
                <Col span="12">
                    <FormItem label="波特率" prop="BAUD">
                        <Select v-model="formValidate.BAUD" placeholder="请选择波特率">
                            <Option :value="item.value" v-for="item in btlList" v-bind:key="item.value">{{ item.label }}</Option>
                        </Select>
                    </FormItem></Col
                >
                <Col span="12">
                    <FormItem label="超时时间" prop="OVERTIME_TIME">
                        <Input type="number" v-model="formValidate.OVERTIME_TIME" placeholder="请输入超时时间"></Input> </FormItem
                ></Col>
            </Row>
            <Row>
                <Col span="12">
                    <FormItem label="帧头字节" prop="HEADER_TYPE">
                        <Input type="text" v-model="formValidate.HEADER_TYPE" placeholder="请输入帧头字节"></Input> </FormItem
                ></Col>
                <Col span="12">
                    <FormItem label="设备回路" prop="EQ_CIRCUIT">
                        <InputNumber
                            :max="1000"
                            :min="0"
                            style="width: 100%"
                            v-model="formValidate.EQ_CIRCUIT"
                            placeholder="请输入设备回路"
                        ></InputNumber> </FormItem
                ></Col>
            </Row>
            <Row>
                <Col span="12">
                    <FormItem label="终端设备型号" prop="EQ_MODEL">
                        <Input v-model="formValidate.EQ_MODEL" placeholder="请输入终端设备型号"></Input>
                    </FormItem>
                </Col>
                <Col span="12">
                    <!-- 设备类型（水、电、空调等分类） -->
                    <FormItem label="设备类型" prop="ENERGY_TYPE">
                        <Select v-model="formValidate.ENERGY_TYPE" placeholder="请选择设备类型" @on-change="ENERGY_TYPEChange">
                            <Option :value="item.value" v-for="item in lylxList" v-bind:key="item.value">{{ item.label }}</Option>
                        </Select>
                    </FormItem></Col
                >
            </Row>
            <Row>
                <Col span="12">
                    <FormItem label="能耗分项" prop="USE_TYPE">
                        <Select v-model="formValidate.USE_TYPE" placeholder="请选择能耗分项" @on-change="ENERGY_FXChange">
                            <Option :value="item.value" v-for="item in nhfxList" v-bind:key="item.value">{{ item.label }}</Option>
                        </Select>
                    </FormItem></Col
                >
                <Col span="12">
                    <FormItem label="一级子项" prop="SUB_TYPE1">
                        <Select v-model="formValidate.SUB_TYPE1" placeholder="请选择一级子项">
                            <Option :value="item.value" v-for="item in yjzxList" v-bind:key="item.value">{{ item.label }}</Option>
                        </Select>
                    </FormItem>
                </Col>
            </Row>

            <Row>
                <Col span="12">
                    <FormItem label="用户自定义子项" prop="SUB_TYPE2">
                        <Select v-model="formValidate.SUB_TYPE2" placeholder="请选择用户自定义子项">
                            <Option :value="item.value" v-for="item in zdyzxList" v-bind:key="item.value">{{ item.label }}</Option>
                        </Select>
                    </FormItem></Col
                >
                <Col span="12">
                    <FormItem label="进行费用计算" prop="IS_COM">
                        <RadioGroup v-model="formValidate.IS_COM">
                            <Radio label="0">否</Radio>
                            <Radio label="1">是</Radio>
                        </RadioGroup>
                    </FormItem>
                </Col>
            </Row>

            <Row>
                <Col span="12">
                    <FormItem label="倍率" prop="RATE">
                        <!-- <Input type="number" v-model="formValidate.RATE" placeholder="请输入倍率" min="0"></Input> -->
                        <InputNumber
                            :max="1000"
                            :min="0"
                            style="width: 100%"
                            v-model="formValidate.RATE"
                            placeholder="请输入倍率"
                        ></InputNumber>
                    </FormItem>
                </Col>
                <Col span="12">
                    <FormItem label="初始读数" prop="INITVALUE">
                        <Input type="text" v-model="formValidate.INITVALUE" placeholder="请输入初始读数"></Input> </FormItem
                ></Col>
            </Row>

            <Row>
                <Col span="12">
                    <FormItem label="初始开始时间" prop="INITTIME">
                        <DatePicker
                            type="date"
                            placeholder="请输入初始开始时间"
                            v-model="formValidate.INITTIME"
                            style="width: 100%"
                        ></DatePicker> </FormItem
                ></Col>

                <Col span="12">
                    <FormItem label="启用分时价格" prop="IS_TIME_PRICE">
                        <RadioGroup v-model="formValidate.IS_TIME_PRICE">
                            <Radio label="0">否</Radio>
                            <Radio label="1">是</Radio>
                        </RadioGroup>
                    </FormItem>
                </Col>
            </Row>

            <Row>
                <Col span="12">
                    <FormItem label="价格方案" prop="PRICE_SCHE_GUID">
                        <Select v-model="formValidate.PRICE_SCHE_GUID" placeholder="请选择价格方案">
                            <Option :value="item.id" v-for="item in jgfaList" v-bind:key="item.id">{{ item.text }}</Option>
                        </Select>
                    </FormItem>
                </Col>
                <Col span="12">
                    <FormItem label="是否支持本地预付费" prop="IS_LOCAL">
                        <RadioGroup v-model="formValidate.IS_LOCAL">
                            <Radio label="0">否</Radio>
                            <Radio label="1">是</Radio>
                        </RadioGroup>
                    </FormItem>
                </Col>
            </Row>
            <Row>
                <Col span="12">
                    <FormItem label="倍率是否写入表计" prop="RATE_WRITE_TAG">
                        <RadioGroup v-model="formValidate.RATE_WRITE_TAG">
                            <Radio label="0">否</Radio>
                            <Radio label="1">是</Radio>
                        </RadioGroup>
                    </FormItem>
                </Col>
                <Col span="12">
                    <FormItem label="是否停用/采集" prop="IS_STOP">
                        <RadioGroup v-model="formValidate.IS_STOP">
                            <Radio label="0">否</Radio>
                            <Radio label="1">是</Radio>
                        </RadioGroup>
                    </FormItem>
                </Col>
            </Row>

            <Row>
                <Col span="12">
                    <FormItem label="排序号" prop="ORDER_NO">
                        <Input type="number" v-model="formValidate.ORDER_NO" placeholder="请输入排序号"></Input>
                    </FormItem>
                </Col>
                <Col span="12">
                    <FormItem label="是否建筑统计" prop="IS_STAT">
                        <RadioGroup v-model="formValidate.IS_STAT">
                            <Radio label="0">否</Radio>
                            <Radio label="1">是</Radio>
                        </RadioGroup>
                    </FormItem></Col
                >
            </Row>
            <Row>
                <Col span="12">
                    <FormItem label="服务器监听IP" prop="TARGET_IP">
                        <Select v-model="formValidate.TARGET_IP" placeholder="服务器监听IP">
                            <Option :value="item" v-for="item in cjIpList" v-bind:key="item">{{ item }}</Option>
                        </Select>
                    </FormItem></Col
                >
                <Col span="12">
                    <FormItem label="监听服务器端口" prop="TARGET_PORT">
                        <Select v-model="formValidate.TARGET_PORT" placeholder="请选择监听服务器端口">
                            <Option :value="item" v-for="item in cjDkList" v-bind:key="item">{{ item }}</Option>
                        </Select>
                    </FormItem></Col
                >
            </Row>
            <Row>
                <Col span="12">
                    <FormItem label="安装地址" prop="INSTALL_ADDRESS">
                        <Input v-model="formValidate.INSTALL_ADDRESS" placeholder="请输入安装地址"></Input> </FormItem
                ></Col>
                <Col span="12">
                    <FormItem label="安装时间" prop="INSTALL_TIME">
                        <DatePicker
                            type="date"
                            placeholder="请选择安装时间"
                            v-model="formValidate.INSTALL_TIME"
                            style="width: 100%"
                        ></DatePicker> </FormItem
                ></Col>
            </Row>
            <FormItem>
                <Button type="primary" @click="handleSubmit('formValidate')">提交</Button>
                <!-- <Button @click="handleReset('formValidate')" style="margin-left: 8px">Reset</Button> -->
            </FormItem>
        </Form>
    </div>
</template>



<script>
import {AjaxCommon} from '@/libs/apiCommon'
import {PopupCommon} from '@/libs/popupCommon'
import {Utility, IconNames} from '@/libs/utility'
import Treeselect from '@riophae/vue-treeselect'
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
import moment from 'moment'
export default {
    props: ['setData', 'allMenu', 'type'],
    components: {Treeselect},
    data() {
        return {
            typeCodeList: [],
            itemMenu: {},
            showIcon: false,
            iconList: [],
            value: null,
            options: [],
            // 采集ip
            cjIpList: [],
            // 采集端口
            cjDkList: [],
            formValidate: {
                EQ_NAME: '',
                EQ_ADDRESS: '',
                GATEWAY_GUID: '',
                EQ_GUID: '',
                PROTOCOL_TYPE: '',
                VALIDATION: 0,
                BAUD: '',
                OVERTIME_TIME: '',
                HEADER_TYPE: '',
                EQ_CIRCUIT: 0,
                EQ_MODEL: '',
                ENERGY_TYPE: '',
                USE_TYPE: '',
                SUB_TYPE1: '',
                SUB_TYPE2: '',
                DOWN_INTERFACE: 0,
                TIME_CONTROL: '0',
                ENCRYPT: '0',
                FACTORY_ID: '',
                IS_COM: '0',
                RATE: 0,
                INITVALUE: '',
                INITTIME: '',
                RATE_WRITE_TAG: '0',
                IS_LOCAL: '0',
                IS_STOP: '1',
                IS_TIME_PRICE: '0',
                PRICE_SCHE_GUID: '',
                // GATEWAYIP: '',
                // GATEWAYPORT: '',
                ORDER_NO: '',
                IS_STAT: '1',
                TARGET_IP: '',
                TARGET_PORT: '',
                INSTALL_TIME: '',
                INSTALL_ADDRESS: '',
                BD_GUID: ''
            },
            ruleValidate: {
                BD_GUID: [{required: true, message: '请选择所属建筑', trigger: 'change'}],
                ORDER_NO: [{required: true, message: '请输入排序号', trigger: 'blur'}],
                OVERTIME_TIME: [{required: true, message: '请输入超时时间', trigger: 'blur'}],
                GATEWAY_GUID: [{required: true, message: '请选择所属网关', trigger: 'change'}],
                EQ_ADDRESS: [{required: true, message: '请输入终端设备地址', trigger: 'blur'}],
                EQ_NAME: [{required: true, message: '请输入终端设备名称', trigger: 'blur'}],
                ENERGY_TYPE: [{required: true, message: '请选择设备类型', trigger: 'change'}],
                USE_TYPE: [{required: true, message: '请选择能耗分项', trigger: 'change'}],
                TARGET_IP: [{required: true, message: '请选择服务器监听IP', trigger: 'change'}],
                TARGET_PORT: [{required: true, message: '请选择服务器监听端口', trigger: 'change'}],
                INSTALL_ADDRESS: [{required: true, message: '请输入安装地址', trigger: 'blur'}],
                INSTALL_TIME: [{required: true, type: 'date', message: '请选择安装时间', trigger: 'change'}],
                DOWN_INTERFACE: [{required: true, message: '请选择下行接口', trigger: 'blur'}],
                BAUD: [{required: true, message: '请选择波特率', trigger: 'change'}],
                PROTOCOL_TYPE: [{required: true, message: '请选择协议类型', trigger: 'change'}],
                VALIDATION: [{required: true, message: '请选择校验方式', trigger: 'change'}],
                //  type: 'number' 这个类型最好能指定，不然经常验证失败，神奇的一堆bug
                RATE: [{required: true, type: 'number', message: '请输入倍率', trigger: 'blur'}]
                // ENCRYPT: [{required: true, message: '请输入是否加密', trigger: ['blur', 'change']}],
                // TIME_CONTROL: [
                //     {
                //         required: true,
                //         message: '请输入是否启用时段控制',
                //         trigger: ['blur', 'change']
                //     },
                //     {
                //         message: '只能包含字母和数字',
                //         trigger: ['blur', 'change'],
                //         pattern: /^[A-Za-z0-9]+$/
                //     }
                // ],
                // GATEWAYIP: [{required: true, message: '请选择采集IP', trigger: ['blur', 'change']}],
                // GATEWAYPORT: [{required: true, message: '请选择采集端口', trigger: ['blur', 'change']}],
                // INSTALL_TIME: [{required: true, type: 'date', message: '请选择安装时间', trigger: ['blur', 'change']}],
                // INSTALL_ADDRESS: [{required: true, message: '请选择安装地址', trigger: ['blur', 'change']}]
            },
            // 所属网关
            sswgList: [],
            // 下行接口
            xxjkList: [],
            // 生产厂家
            sccjList: [],
            // 协议类型
            xylxList: [],
            // 校验方式
            jyfsList: [],
            // 波特率
            btlList: [],
            // 设备类型
            lylxList: [],
            // 能耗分项
            nhfxList: [],
            // 一级子项
            yjzxList: [],
            // 自定义子项
            zdyzxList: [],
            /** 价格方案 */
            jgfaList: []
        }
    },
    methods: {
        // 设备类型change
        ENERGY_TYPEChange(e) {
            this.GetUseTypeByEqType(e)
            this.GetSubTypeCustom(e)
        },
        /**
         * 获取用户自定义分项  （只跟设备类型有关）
         * @param subType
         */
        async GetSubTypeCustom(subType) {
            // 接口报错
            const res = await AjaxCommon(`/api/Eq/GetUserSubItem?subType=${subType}`, 'get', null)
            const data = res?.data?.Message?.map((t) => {
                return {
                    value: t.dic_value,
                    label: t.dic_desc
                }
            })
            this.zdyzxList = data
        },
        // 能耗分项
        async GetUseTypeByEqType(e) {
            this.yjzxList = []
            const eqType = await AjaxCommon(`/api/Eq/GetUseTypeByEqType/${e}`, 'get', null)
            const data = eqType.data.Message
            if (data && data.length > 0) {
                const item = data[0]
                this.nhfxList = data?.map((t) => {
                    return {
                        value: t.DIC_VALUE,
                        label: t.DIC_DESC
                    }
                })
                this.formValidate.USE_TYPE = item.DIC_VALUE
                this.GetSubType(e, item.DIC_VALUE)
            } else {
                this.nhfxList = []
                this.yjzxList = []
                this.formValidate.USE_TYPE = ''
                this.formValidate.SUB_TYPE1 = ''
            }
        },
        // 能耗分项改变事件
        ENERGY_FXChange(e) {
            // 改变一级子项 GetSubType
            // 设备类型 this.formValidate.ENERGY_TYPE
            if (e) {
                this.GetSubType(this.formValidate.ENERGY_TYPE, e)
            }
        },

        async GetSubType(eqType, item) {
            const subType = await AjaxCommon(`/api/Eq/GetSubType/${eqType}/${item}`, 'get', null)
            const data = subType.data.Message
            if (data && data.length > 0) {
                const item1 = data[0]
                this.formValidate.SUB_TYPE1 = item1.dic_value
                this.yjzxList = data?.map((t, i) => {
                    return {
                        value: t.dic_value,
                        label: t.dic_desc
                    }
                })
            } else {
                this.formValidate.SUB_TYPE1 = ''
            }
        },
        handleSubmit(name) {
            this.$refs[name].validate((valid) => {
                if (valid) {
                    // const yjzxList = this.yjzxList
                    // this.formValidate.SUB_TYPE1 = parseInt(yjzxList.find((t) => t.value == this.formValidate.SUB_TYPE1).value1)
                    // 协议类型
                    const xylx = this.xylxList
                    const PROTOCOL_TYPE = this.formValidate.PROTOCOL_TYPE
                    this.formValidate.PROTOCOL_TYPE = xylx.find((t) => t.value == PROTOCOL_TYPE).id
                    // 校验方式
                    const jyfs = this.jyfsList
                    const VALIDATION = this.formValidate.VALIDATION
                    this.formValidate.VALIDATION = jyfs.find((t) => t.value == VALIDATION).id
                    // 波特率
                    const btl = this.btlList
                    const baud = this.formValidate.BAUD
                    this.formValidate.BAUD = btl.find((t) => t.value == baud).id
                    // 下行接口
                    const xxjk = this.xxjkList
                    const DOWN_INTERFACE = this.formValidate.DOWN_INTERFACE
                    this.formValidate.DOWN_INTERFACE = xxjk.find((t) => t.value == DOWN_INTERFACE).id
                    let INITTIME = this.formValidate.INITTIME
                    let INSTALL_TIME = this.formValidate.INSTALL_TIME
                    if (INITTIME) {
                        INITTIME = moment(INITTIME).format('YYYY-MM-DD')
                        this.formValidate.INITTIME = INITTIME
                    }
                    if (INSTALL_TIME) {
                        INSTALL_TIME = moment(INSTALL_TIME).format('YYYY-MM-DD')
                        this.formValidate.INSTALL_TIME = INSTALL_TIME
                    }
                    // 倍率 RATE
                    if (this.formValidate.RATE) {
                        this.formValidate.RATE = parseInt(this.formValidate.RATE)
                    }
                    // 初始读数 INITVALUE
                    if (this.formValidate.INITVALUE) {
                        this.formValidate.INITVALUE = parseFloat(this.formValidate.INITVALUE)
                    }
                    if (this.formValidate.ORDER_NO) {
                        this.formValidate.ORDER_NO = parseFloat(this.formValidate.ORDER_NO)
                    }
                    if (this.formValidate.OVERTIME_TIME) {
                        this.formValidate.OVERTIME_TIME = parseFloat(this.formValidate.OVERTIME_TIME)
                    }
                    if (this.formValidate.EQ_CIRCUIT) {
                        this.formValidate.EQ_CIRCUIT = parseFloat(this.formValidate.EQ_CIRCUIT)
                    }

                    delete this.formValidate.COM_FORMULA
                    delete this.formValidate.CUSTOM_TYPE
                    delete this.formValidate.EQ_FULL_NAME
                    delete this.formValidate.FREEZE_NO
                    delete this.formValidate.FREEZE_NUM
                    delete this.formValidate.INIT_COM_TIME
                    delete this.formValidate.INIT_TIME
                    delete this.formValidate.INIT_VALUE
                    delete this.formValidate.WLP_GUID
                    delete this.formValidate.WRITE_COUNT
                    delete this.formValidate.buildName
                    delete this.formValidate.INSTALL_PIC_GUID
                    delete this.formValidate.IS_BALANCE_AY
                    delete this.formValidate.IS_BELONG
                    delete this.formValidate.IS_DELETE
                    delete this.formValidate.IS_ENABLE_LOCAL
                    delete this.formValidate.IS_ENCRYPT
                    delete this.formValidate.IS_FLOW_BACK
                    delete this.formValidate.IS_FREE_WRITE
                    delete this.formValidate.IS_LADDER_PRICE
                    delete this.formValidate.IS_ONLINE
                    delete this.formValidate.IS_OPEN
                    delete this.formValidate.IS_TIME_CONTROL
                    delete this.formValidate.IS_VIRTUAL
                    delete this.formValidate.LADDER_PRICE_GUID
                    delete this.formValidate.LATELY_ONLINE_TIME
                    delete this.formValidate.ONLINE_TIME
                    delete this.formValidate.OPER_TIME
                    delete this.formValidate.OPER_USER
                    delete this.formValidate.IS_MANUAL
                    delete this.formValidate.STAT_CYCLE
                    delete this.formValidate.STOP_TIME
                    delete this.formValidate.SWITCH_STATE
                    delete this.formValidate.SWITCH_TIME
                    delete this.formValidate.EQ_TYPE
                    delete this.formValidate.ORG_ID
                    delete this.formValidate.PARENT_EQ_GUID
                    // const newData = this.formValidate
                    this.$emit('getData', JSON.stringify(this.formValidate))
                }
            })
        },
        // handleReset(name) {
        //     this.$refs[name].resetFields()
        // }
        async initParentMenu() {
            const allBuild = await AjaxCommon(`/api/Build/GetAllBuild`, 'get', null)
            console.log(allBuild)
            const buildList = allBuild?.data?.Message ?? []
            let allBuildTree = []
            if (buildList.length > 0) {
                allBuildTree = Utility.arrayCascade(buildList, (c, p) => c.PARENT_BD_GUID == p.BD_GUID, 'children')
            }
            if (allBuildTree && allBuildTree.length > 0) {
                let treeDataList = []
                Utility.createBuildTreeData(allBuildTree, treeDataList)
                if (treeDataList && treeDataList.length > 0) {
                    this.options = [
                        {
                            id: '',
                            label: '顶级建筑'
                        }
                    ].concat(treeDataList)
                }
            } else {
                this.options = [
                    {
                        id: '',
                        label: '顶级建筑'
                    }
                ]
            }
        },
        async initData() {
            const self = this
            // 所属网关
            AjaxCommon(`/api/Eq/GetEquipmentTree?type=all&eqid=&gateway_guid=&PageSize=1000&PageIndex=1`, 'get', null).then((res) => {
                if (res?.data?.Code == 200) {
                    const data = res?.data.Message?.[0]
                    const newData = data?.rows?.filter((t) => t.type == 'gateway')
                    // text id
                    self.sswgList = newData
                }
            })

            // 价格方案  api/Eq/GetPriceSchemesPage?PageSize=20&PageIndex=1
            const priceRes = await AjaxCommon(`/api/Eq/GetPriceSchemesPage?PageSize=1000&PageIndex=1`, 'get', null)
            if (priceRes?.data?.Code == 200) {
                const data = priceRes?.data.Message?.rows
                // text id
                self.jgfaList = data
            }

            // api/Eq/GetFreezeDataDics   产品型号、校验方式、波特率
            const freezeDataDics = await AjaxCommon(`/api/Eq/GetFreezeDataDics`, 'get', null)
            console.log(freezeDataDics)
            const freezeDataDicsItem = freezeDataDics.data.Message
            // btlList
            const btl = freezeDataDicsItem?.btl
            this.btlList = btl?.map((t) => {
                return {
                    value: t.fieldValue,
                    id: t.fieldId,
                    label: t.fieldValue
                }
            })
            // 校验方式 jyfsList
            const jyfs = freezeDataDicsItem?.jyfs
            this.jyfsList = jyfs?.map((t) => {
                return {
                    value: t.fieldValue,
                    id: t.fieldId,
                    label: t.fieldValue
                }
            })
            // 协议类型 xylxList
            const xylx = freezeDataDicsItem?.xylx
            this.xylxList = xylx?.map((t) => {
                return {
                    value: t.fieldValue,
                    id: t.fieldId,
                    label: t.fieldValue
                }
            })
            // 下行接口
            const xxjk = freezeDataDicsItem?.xxjk
            this.xxjkList = xxjk?.map((t) => {
                return {
                    value: t.fieldValue,
                    id: t.fieldId,
                    label: t.fieldValue
                }
            })

            // 设备类型 lylxList 和 生产厂家 sccjList
            AjaxCommon(`/api/Eq/GetDataDicsForEq`, 'get', null).then((res) => {
                const lylxList = (res.data.Message.sblx ?? [])?.map((t) => {
                    return {
                        value: t.DIC_VALUE,
                        label: t.DIC_DESC
                    }
                })
                const sccjList = (res.data.Message.sccj ?? [])?.map((t) => {
                    return {
                        value: t.DIC_VALUE,
                        label: t.DIC_DESC
                    }
                })
                this.lylxList = lylxList
                this.sccjList = sccjList
            })

            // // 自定义子项 E_SUBITEM_TYPE_USER
            // Utility.getDictListByTypeCode('E_SUBITEM_TYPE_USER').then((res) => {
            //     if (res && res.length > 0) {
            //         const data = res.map((t) => {
            //             return {
            //                 value: t.value,
            //                 label: t.desc
            //             }
            //         })
            //         this.zdyzxList = data
            //     }
            // })

            const EQ_TYPE = this.setData.EQ_TYPE
            if (EQ_TYPE) {
                await this.GetSubTypeCustom(EQ_TYPE)
            }

            // IP和端口LIST
            AjaxCommon('/api/ServiceConfig/GetWebIpAndPort', 'get', null).then((res) => {
                this.cjIpList = res.data.Message?.ip?.map((t) => t.id)
                this.cjDkList = res.data.Message?.port?.map((t) => t.id)
            })

            // 处理设备类型、能耗分项、一级子项
            if (this.type == 'edit') {
                // 处理校验方式、
                this.setData.ENERGY_TYPE = this.setData.EQ_TYPE
                this.setData.TIME_CONTROL = this.setData.IS_TIME_CONTROL
                this.setData.ENCRYPT = this.setData.IS_ENCRYPT
                this.setData.INITVALUE = this.setData.INIT_VALUE
                this.setData.INITTIME = this.setData.INIT_TIME
                const DOWN_INTERFACE = this.setData.DOWN_INTERFACE
                const VALIDATION = this.setData.VALIDATION
                const BAUD = this.setData.BAUD
                const PROTOCOL_TYPE = this.setData.PROTOCOL_TYPE
                const xxjkList = this.xxjkList
                const jyfsList = this.jyfsList
                const btlList = this.btlList
                const xylxList = this.xylxList
                this.setData.DOWN_INTERFACE = xxjkList.find((t) => t.id == DOWN_INTERFACE)?.value ?? ''
                this.setData.VALIDATION = jyfsList.find((t) => t.id == VALIDATION)?.value ?? ''
                this.setData.BAUD = btlList.find((t) => t.id == BAUD)?.value ?? ''
                this.setData.PROTOCOL_TYPE = xylxList.find((t) => t.id == PROTOCOL_TYPE)?.value ?? ''
                const setData = this.setData
                const ENERGY_TYPE = setData.ENERGY_TYPE
                const USE_TYPE = setData.USE_TYPE
                if (ENERGY_TYPE) {
                    const eqType = await AjaxCommon(`/api/Eq/GetUseTypeByEqType/${ENERGY_TYPE}`, 'get', null)
                    const data = eqType.data.Message
                    if (data && data.length > 0) {
                        this.nhfxList = data?.map((t) => {
                            return {
                                value: t.DIC_VALUE,
                                label: t.DIC_DESC
                            }
                        })
                        // this.formValidate.USE_TYPE = item.DIC_VALUE
                        // this.GetSubType(e, item.DIC_VALUE)
                    } else {
                        this.formValidate.USE_TYPE = ''
                        this.formValidate.SUB_TYPE1 = ''
                    }
                }
                if (ENERGY_TYPE && USE_TYPE) {
                    const subType = await AjaxCommon(`/api/Eq/GetSubType/${ENERGY_TYPE}/${USE_TYPE}`, 'get', null)
                    const data = subType.data.Message
                    if (data && data.length > 0) {
                        this.yjzxList = data?.map((t, i) => {
                            return {
                                value: t.dic_value,
                                label: t.dic_desc
                            }
                        })
                    } else {
                        this.formValidate.SUB_TYPE1 = ''
                    }
                }
            }

            // setTimeout(() => {
            // 编辑 或 新增子级
            if (this.setData && this.type == 'edit') {
                this.formValidate = this.setData

                if (this.formValidate.EQ_CIRCUIT) {
                    this.formValidate.EQ_CIRCUIT = parseFloat(this.formValidate.EQ_CIRCUIT)
                }

                // 倍率 RATE
                if (this.formValidate.RATE) {
                    this.formValidate.RATE = parseInt(this.formValidate.RATE)
                }
                // 初始读数 INITVALUE
                if (this.formValidate.INITVALUE) {
                    this.formValidate.INITVALUE = parseFloat(this.formValidate.INITVALUE)
                }
            }
            // }, 1000)
        }
    },
    created() {
        this.initData()

        this.initParentMenu()
    },
    mounted() {
        this.$nextTick(() => {})
    }
}
</script>

<style lang="scss">
.selectIcon {
    position: absolute;
    top: 0px;
    left: 0;
    width: 100%;
    height: 156px;
    z-index: 999999;
    border: 1px solid #e0e0e0;
    background: #fff;
    border-radius: 4px;
    padding: 4px;
    overflow-y: auto;
    overflow-x: hidden;
    .bi {
        margin-right: 10px;
        margin-bottom: 10px;
        cursor: pointer;
    }
}
</style>
